<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>税号信息选择页面</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript" src="/js/semanticUI/dist/semantic.min.js"></script>
<script type="text/javascript">
    var formSetting = {
        title: "税号信息选择",
        module: 'query',
        numCount: '2',
        columns: [{
            index: "NAME",
            name: "name",
            label: "货物名称"
        }, {
            index: "CODE_T",
            name: "code_t",
            label: "税号"
        }, {
            index: "GOODS_MODE",
            name: "goods_mode",
            label: "要素"
        }],
        buttons: {
            custom: [{
                id: "confirmbtn",
                value: "确定",
                click: function () {
                    var id = $("#goodsViewDataGrid").jqGrid("getGridParam",
                                                            "selrow");
                    if (id) {
                        var rowData = $("#goodsViewDataGrid").jqGrid('getRowData', id);
                        var name = rowData.name;
                        var code_t = rowData.code_t;
                        var code_s = rowData.code_s;
                        var goods_mode = rowData.goods_mode;
                        var unit = rowData.unit;
                        var unitCode = rowData.unitCode;
                        var second_unit = rowData.second_unit;
                        var secondUnitCode = rowData.secondUnitCode;
                        var legal_unit = rowData.legal_unit;
                        var legalUnitCode = rowData.legalUnitCode;
                        if ('${type}' == '3.0') {
                            $('#name', parent.document).val(name);
                            $("#code_t", parent.document).parent().dropdown("set text",
                                                                            code_t
                                                                            + code_s);
                            $('#code_t', parent.document).val(code_t);
                            $('#code_s', parent.document).val(code_s);
//                            $('#key_elements', parent.document).val(goods_mode);
                            $('#goods_mode', parent.document).val(goods_mode);

                            $('#legalUnitCode', parent.document).parent().dropdown("set text",
                                                                                   legal_unit);
                            $('#legalUnitCode', parent.document).val(legalUnitCode);
                            $('#legal_unit', parent.document).val(legal_unit);

                            $('#unitCode', parent.document).parent().dropdown("set text", unit);
                            $('#unitCode', parent.document).val(unitCode);
                            $('#unit', parent.document).val(unit);

                            if (second_unit && second_unit != "") {
                                $('#secondUnitCode', parent.document).parent().dropdown("set text",second_unit);
                                $('#secondUnitCode', parent.document).val(secondUnitCode);
                                $('#second_unit', parent.document).val(second_unit);
                            } else {
                                $('#secondUnitCode', parent.document).parent().dropdown("set text","");
                                $('#secondUnitCode', parent.document).val("");
                                $('#second_unit', parent.document).val("");
                            }
                            parent.addOrRemoveSecondRequired(second_unit && second_unit != "");

                            parent.layer.closeAll();
                        } else {
                            $('#GOODS_MODE', parent.document).val(goods_mode);
                            $('#CODE_T', parent.document).val(code_t);
                            $('#CODE_S', parent.document).val(code_s);
                            $('#NAME', parent.document).val(name);
                            $('#UNIT', parent.document).val(unit);
                            $('#LEGAL_UNIT', parent.document).val(legal_unit);
                            if (!second_unit || second_unit == "") {
                                $("#SECOND_COUNT", parent.document).attr("disabled", true);
                                $("#SECOND_COUNT", parent.document).attr("class", "disableInput");
                            } else {
                                $("#SECOND_COUNT", parent.document).attr("disabled", false);
                                $("#SECOND_COUNT", parent.document).attr("class", "");
                            }
                            $('#SECOND_UNIT', parent.document).val(second_unit);
                            jw.close();
                        }

                    } else {
                        jw.alert("请点击需要操作的数据!");
                    }
                }
            }]
        },
        grid: {
            id: "goodsViewDataGrid",
            title: "查询结果",
            url: "./goodsView-findList?goodsViewName=" + decodeURIComponent("${goodsViewName}"),
            colModel: [{
                index: "id",
                name: "id",
                label: "id",
                hidden: true
            }, {
                index: "name",
                name: "name",
                label: "货物名称"
            }, {
                index: "code_t",
                name: "code_t",
                label: "税号"
            }, {
                index: "code_s",
                name: "code_s",
                label: "税号附号"
            }, {
                index: "goods_mode",
                name: "goods_mode",
                label: "规格型号"
            }, {
                index: "unit",
                name: "unit",
                label: "计价单位",
                hidden: true
            }, {
                index: "second_unit",
                name: "second_unit",
                label: "第二计量单位",
                hidden: true
            }, {
                index: "legal_unit",
                name: "legal_unit",
                label: "法定单位",
                hidden: true
            }, {
                index: "unitCode",
                name: "unitCode",
                label: "计价单位编码",
                hidden: true
            }, {
                index: "secondUnitCode",
                name: "secondUnitCode",
                label: "第二计量单位编码",
                hidden: true
            }, {
                index: "legalUnitCode",
                name: "legalUnitCode",
                label: "法定单位编码",
                hidden: true
            }]
            //sortname: "code_t",
            //sortorder: "desc"
        }
    };
    $(document).ready(function () {
        $("#goodsViewDataTable").mrdForm(formSetting);
        $("#goodsViewDataTable").mrdForm("resize");
    });
</script>
<body>
<div id="goodsViewDataTable"></div>
</body>
</html>
